package es.cazadoresmadridejos.beans.controller.adviced;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import es.cazadoresmadridejos.beans.manager.adviced.AdvicedManager;
import es.cazadoresmadridejos.model.Adviced;
import es.cazadoresmadridejos.propertyeditor.AdvicedPropertyEditor;
import es.cazadoresmadridejos.util.constants.Constants;

@Controller
public class AdvicedProfileController {

	@Autowired private AdvicedManager advicedManager;
	
	@InitBinder
	public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Throwable{
		binder.registerCustomEditor(Adviced.class, new AdvicedPropertyEditor(advicedManager));
		binder.registerCustomEditor(Date.class, "date",new CustomDateEditor(Constants.sdf,true));
	}
	
	
	@RequestMapping("/advicedProfile.html")
	public ModelAndView profile(
			@RequestParam("id")Adviced adviced
			){
		ModelAndView mv = new ModelAndView("advicedCreateModify");
		
		mv.addObject("adviced", adviced);
		mv.addObject("type", "profile");
		
		return mv;
	}
}
